package info.motteke.qjdbc.column.variable;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;

public final class TimestampVariable extends Variable {

    private long timestamp;

    private boolean set = false;

    public TimestampVariable() {

    }

    public TimestampVariable(Date timestamp) {
        is(timestamp);
    }

    public void is(Date timestamp) {
        this.timestamp = timestamp.getTime();
        set = true;
    }

    @Override
    void putValue(PreparedStatement pstmt, int index) throws SQLException {
        if (!set) {
            throw new IllegalStateException();
        }

        pstmt.setTimestamp(index, new Timestamp(timestamp));
    }

}
